package dao;


import entity.UpFile;
import org.apache.commons.dbutils.BasicRowProcessor;
import org.apache.commons.dbutils.GenerousBeanProcessor;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import utils.DataSourceUtils;

import javax.sql.DataSource;
import java.io.File;
import java.math.BigInteger;
import java.sql.SQLException;
import java.util.List;

public class FileDao {
    public static List<UpFile> selectALl() throws SQLException {
        QueryRunner queryRunner = new QueryRunner();
        String sql = "select * from kfm_file";
        return queryRunner.query(DataSourceUtils.getConnection(),sql, new BeanListHandler<>(UpFile.class));
    }

    public static int addSql(String name , long Size , String upload_ip, String download_link) throws SQLException {
        QueryRunner queryRunner = new QueryRunner();
        String sql = "INSERT INTO kfm_file (name,size,create_time,upload_ip,download_link) values (?,?,NOW(),?,?) ";
        return queryRunner.update(DataSourceUtils.getConnection(), sql, name, Size, upload_ip, download_link);
    }
    /**
     * 删除某个数据
     */
    public static int delete(String id) throws SQLException {
        QueryRunner queryRunner = new QueryRunner();
        String sql = "DELETE FROM kfm_file WHERE id = ?";
        return queryRunner.update(DataSourceUtils.getConnection(), sql, id);
    }
}
